﻿using MyCrypto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace DX_sharq.Models
{
    public class SecurityForAttributeAdmin : ActionFilterAttribute
    {
        Crypto _crypto = new Crypto();
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            bool b = false;
            if (filterContext.HttpContext.Request.Cookies["_C"] != null)
            {

                HttpCookie cookie = filterContext.HttpContext.Request.Cookies["_C"];
                string _guid = cookie.Value;
                int bulim_type = Convert.ToInt32(HttpContext.Current.Session[_guid + "_bul_t"]);
                //int bulim_type = Convert.ToInt32(_crypto.Decrypt(cookie2.Value, _crypto.sharedSec));                    
                if (bulim_type == 2)
                {
                    b = true;
                }
            }
            else
            {
                b = false;
            }

            if (!b)    // birinchi shu erga keladi
            {
                string url = filterContext.HttpContext.Request.Url.ToString();
                string ss = filterContext.RequestContext.HttpContext.Request.QueryString["mess"];
                filterContext.HttpContext.Response.Redirect("/account/LogOn/?mess=" + ss + "&returnUrl=" + url);
            }
        }
    }
}